//
//  HYInfoCell.m
//  HaiYue
//
//  Created by skyline on 2018/2/5.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "HYInfoFloorCell.h"
#import "HYAuthorView.h"
@interface HYInfoFloorCell()
@property (nonatomic, strong) HYLabel *titleLBL;
@property (nonatomic, strong) HYImageView *IMG;
@property (nonatomic, strong) HYLabel *contentLBL;
@property (nonatomic, strong) HYAuthorView *authorView;
@end
@implementation HYInfoFloorCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.separatorInset = UIEdgeInsetsZero;
    }
    return self;
}

- (HYLabel *)titleLBL
{
    if (!_titleLBL)
    {
        _titleLBL= [[HYLabel alloc] initWithText:@"" textColor:TEXT_BLACK_COLOR textFont:[UIFont systemFontOfSize:TitleFont weight:UIFontWeightBold]];
        _titleLBL.fixedWidth = SCREEN_WIDTH - 2 * GAP;
        [self addSubview:_titleLBL];
        [_titleLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(GAP);
            make.top.equalTo(self).with.offset(GAP);
        }];
    }
    return _titleLBL;
}

- (HYImageView *)IMG
{
    if (!_IMG)
    {
        _IMG = [[HYImageView alloc] init];
        _IMG.backgroundColor = THEME_COLOR;
        [self addSubview:_IMG];
        [_IMG mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.titleLBL.mas_bottom).with.offset(GAP);
            make.left.equalTo(self).with.offset(GAP);
            make.right.equalTo(self).with.offset(-GAP);
            make.height.mas_equalTo(1);
        }];
    }
    return _IMG;
}

- (HYLabel *)contentLBL
{
    if (!_contentLBL)
    {
        _contentLBL = [[HYLabel alloc] initWithText:@"" textColor:TEXT_GRAY_COLOR textFont:[UIFont systemFontOfSize:DefaultFont]];
        _contentLBL.numberOfLines = 3;
        _contentLBL.fixedWidth = SCREEN_WIDTH - 2 * GAP;
        [self addSubview:_contentLBL];
        [_contentLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(GAP);
            make.top.equalTo(self.IMG.mas_bottom).with.offset(GAP);
        }];
    }
    return _contentLBL;
}

- (HYAuthorView *)authorView
{
    if (!_authorView)
    {
       _authorView = [[HYAuthorView alloc] init];
        [self addSubview:_authorView];
        [_authorView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentLBL.mas_bottom).with.offset(GAP);
            make.left.equalTo(self);
            make.size.mas_equalTo(self.authorView.bounds.size);
        }];
    }
    return _authorView;
}

- (void)setDict:(NSDictionary *)dict
{
    if (_dict != dict)
    {
        _dict = dict;
        self.titleLBL.text = [_dict valueForKey:@"title"];
        self.IMG.image = [UIImage imageNamed:[_dict valueForKey:@"imageName"]];
        self.contentLBL.text = [_dict valueForKey:@"content"];
        self.authorView.dict = _dict;
        
        CGSize size = [self.IMG getFixSizeWithH:SCREEN_WIDTH - GAP * 2];
        self.IMG.bounds = CGRectMake(0, 0, size.width, size.height);
        [self.IMG mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(size.height);
        }];
        
        [self updateBounds];
    }
}

- (void)updateBounds
{
    CGFloat height = CGRectGetHeight(self.titleLBL.bounds) + CGRectGetHeight(self.IMG.bounds) + CGRectGetHeight(self.contentLBL.bounds) + CGRectGetHeight(self.authorView.bounds) + GAP * 5.0;
    self.bounds = CGRectMake(0, 0, SCREEN_WIDTH, height);
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    // Initialization code
}

//这里设置bgView或者contentview的颜色，等于cell高亮状态的颜色
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    [super setHighlighted:highlighted animated:animated];
    self.selectedBackgroundView = [[HYView alloc] initWithColor:RGBA(120,230,220,0.3)];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
